package org.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.chen.common.vo.ResultVO;
import org.chen.entity.Model;
import org.chen.entity.Voice;
import org.chen.query.ModelQueryParams;
import org.chen.query.VoiceQueryParams;
import org.chen.request.VoiceRequest;
import org.chen.service.VoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/voice")
@RestController
public class VoiceController {

    @Autowired
    private VoiceService voiceService;

    @PostMapping("/add")
    public ResultVO<Voice> addCategory(
            @RequestBody VoiceRequest voiceRequest) {

        try {
            Voice voice = voiceService.saveVoice(voiceRequest);
            return ResultVO.success("添加音色成功", voice);
        } catch (Exception e) {
            return ResultVO.fail("添加音色失败：" + e.getMessage());
        }
    }

    @GetMapping("/list")
    public ResultVO<Page<Voice>> list(VoiceQueryParams queryParams) {

        System.out.println("打印Voice queryParams" + queryParams);
        try {
            Page<Voice> page = voiceService.queryVoices(queryParams);
            return ResultVO.success("查询音色成功", page);
        } catch (Exception e) {
            return ResultVO.fail("查询音色失败：" + e.getMessage());
        }
    }

    @GetMapping("/getDetail/{id}")
    public ResultVO<Voice> getDetailById(@PathVariable String id) {

        System.out.println("打印VoiceId" + id);
        try {
            Voice voice = voiceService.getById(id);
            return ResultVO.success("查询模型成功", voice);
        } catch (Exception e) {
            return ResultVO.fail("查询模型失败：" + e.getMessage());
        }
    }
}
